<?php

namespace app\index\controller;

use app\index\Controller;
use think\Db;

/**
 * @title 车辆管理（模块16）
 * @description 接口说明
 * @groupremark 已使用错误码： 1010001 1010002 1010003 1010004 1010005 1010006 1010007 1010008 1010009 1010010 1010011 1010012 1010013 1010014 1010015 1010016
 * @group 用户
 * @header name:model_id   default:01 desc:模块id
// * @param name:token type:string   default:  other: desc: token
 */

class Arctic extends Controller
{
    /**
     * @title 获取车型列表
     * @description 接口说明
     * @author 邓汉炜
     * @url /index/arctic/get_arctic
     * @method ~
     * @param name:token type:string require:1 default: desc:用户token
     * @return data:车型列表@!
     * @data id:车类型id name:车类型名称
     * @return error_id: 1010001 获取失败
     */
    public function get_arctic()
    {
        // 查询车型
        $list = Db::name('arctic')->field('id,name')->where('isdelete',0)->select();
        if ($list) {
            $msg['message'] = '获取数据成功,如果没有合适你的车型,请联系管理员添加';
            $msg['list'] = $list;
            return $this->success($msg);
        }else{
            $msg['error_id'] = 1010001;
            $msg['message'] = '获取数据失败';
            $msg['list'] = [];
            return $this->error($msg);
        }
    }

    /**
     * @title 获取车辆品牌列表
     * @description 根据车型id获取车辆品牌
     * @author 邓汉炜
     * @url /index/arctic/get_car_brand_list
     * @method ~
     * @param name:token type:string require:1 default: desc:用户token
     * @param name:arctic_id type:int require:1 default: desc:车类型id
     * @return data:车辆品牌列表@!
     * @data id:车辆品牌id arctic_id:车类型id brand_name:车辆品牌名称
     * @return error_id: 1010001 校验失败 1010002 获取失败
     */
    public function get_car_brand_list()
    {
        $data = input();
        //验证数据
        if (!$data['arctic_id']){
            $msg['error_id'] = 1010001;
            $msg['message'] = '缺少车型id';
            return $this->error($msg);
        }
        // 获取数据
        $list = Db::name('car_brand')->where('arctic_id',$data['arctic_id'])->where('isdelete',0)->field('id,arctic_id,brand_name')->select();
        if ($list){
            $msg['message'] = '获取数据成功,如果没有合适你的车辆品牌,请联系管理员添加';
            $msg['list'] = $list;
            return $this->success($msg);
        }else{
            $msg['error_id'] = 1010002;
            $msg['message'] = '该车型下没有品牌,请联系管理员进行添加';
            $msg['list'] = [];
            return $this->error($msg);
        }
    }

    /**
     * @title 获取汽车型号列表
     * @description 根据车辆品牌id获取汽车型号列表
     * @author 邓汉炜
     * @url /index/arctic/get_car_model_list
     * @method ~
     * @param name:token type:string require:1 default: desc:用户token
     * @param name:car_brand_id type:int require:1 default: desc:车辆品牌id
     * @return data:汽车型号列表@!
     * @data id:汽车型号id arctic_id:车类型id car_brand_id:车辆品牌id seat:汽车座位数 car_model:汽车型号名称
     * @return error_id: 1010001 校验失败 1010002 获取失败
     */
    public function get_car_model_list()
    {
        $data = input();
        if (!$data['car_brand_id']){
            $msg['error_id'] = 1010001;
            $msg['message'] = '缺少车辆品牌id';
            return $this->error($msg);
        }
        // 获取数据
        $list = Db::name('car_model')->where('car_brand_id',$data['car_brand_id'])->where('isdelete',0)
            ->field('isdelete,create_time',true)->select();
        if ($list) {
            $msg['message'] = '获取数据成功,如果没有合适您的汽车型号,请联系管理员添加';
            $msg['list'] = $list;
            return $this->success($msg);
        }else{
            $msg['error_id'] = 1010002;
            $msg['message'] = '该车辆品牌下没有汽车型号,请联系管理员进行添加';
            $msg['list'] = [];
            return $this->error($msg);
        }
    }
}
